﻿//
// Created by francklinson on 2021/3/23.
// stonewt.cpp -- StoneWt methods

#include <iostream>

using std::cout;

#include "stoneWt.h"

// construct StoneWt object from double value
StoneWt::StoneWt(double lbs)
{
    stone = int(lbs) / Lbs_per_stn; // integer division
    pds_left = int(lbs) % Lbs_per_stn + lbs - int(lbs);
    pounds = lbs;
}

// construct StoneWt object from stone, double values
StoneWt::StoneWt(int stn, double lbs)
{
    stone = stn;
    pds_left = lbs;
    pounds = stn * Lbs_per_stn + lbs;
}

StoneWt::StoneWt() // default constructor, wt = 0
{
    stone = pounds = pds_left = 0;
}

StoneWt::~StoneWt() // destructor
= default;

// show weight in stones
void StoneWt::show_stn() const
{
    cout << stone << " stone, " << pds_left << " pounds\n";
}

// show weight in pounds
void StoneWt::show_lbs() const
{
    cout << pounds << " pounds\n";
}

// conversion functions
StoneWt::operator int() const
{

    return int(pounds + 0.5);

}

StoneWt::operator double() const
{
    return pounds;
}